package com.xspace.android.imcommon.interfaces;

import android.content.Context;
import android.content.Intent;

public class ImServiceConnection {
	private static ImServiceConnection imMessage;
	private static ServiceManager mServiceManager;

	public static void ClearService(){
		imMessage=null;
		mServiceManager=null;
	}
	private ImServiceConnection() {
	}

	public synchronized static ImServiceConnection getInstance() {
		if (mServiceManager == null) {
			throw new IllegalStateException("it must call init method.");
		}
		if (imMessage == null)
			imMessage = new ImServiceConnection();
		return imMessage;
	}

	public static void init(Context context, String serviceName) {
		mServiceManager =mServiceManager.getInstance(context,
				serviceName);
	}

	public  static void stop() {
		if(mServiceManager!=null)
		mServiceManager.unbindService();
	}
	public  static boolean stopService(Context context, String serviceName) {
		if(context!=null){
		Intent in=	new Intent(serviceName);
		in.setPackage(context.getPackageName());
		return context.stopService(in);
		}
		return false;
	}
	public ServiceManager getImServiceConnection() {
		return mServiceManager;
	}

}